import time
from concurrent.futures import ThreadPoolExecutor


def task(name: str):
    print(f"{name} step 1\n", end="")
    time.sleep(0.1)
    print(f"{name} step 2\n", end="")
    return f"{name} complete"


with ThreadPoolExecutor() as executor:
    result1 = executor.submit(task, "A")
    result2 = executor.submit(task, "B")

    # 这里的result() 会等待线程执行完毕 再执行
    print(result1.result())
    print(result2.result())


with ThreadPoolExecutor() as executor:
    results = executor.map(task, ["C", "D"])

    for r in results:
        print(r)  # 获取线程的返回值
